<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="sidebar.collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
      :collapse-transition="false"
    >
      <template v-for="item in menuList">
        <template v-if="item.children">
            <el-sub-menu :index="item.path" :key="item.path">
              <template #title>
                <el-icon>
                  <svg-icon :name="item.icon" fill="#fff" />
                </el-icon>
                <span>{{ item.name }}</span>
              </template>
              <template v-for="subItem in item.children">
                <template v-if="subItem.children.length">
                  <el-sub-menu :index="subItem.path" :key="subItem.path" v-if="subItem.isShow">
                    <template #title>
                      <el-icon>
                        <svg-icon :name="subItem.icon" fill="#fff" />
                      </el-icon>
                      {{ subItem.name }}
                    </template>
                    <template
                      v-for="subItem2 in subItem.children"
                      :key="subItem2.path"
                    >
                      <el-menu-item :index="subItem2.path"   v-if="subItem2.isShow">
                        <el-icon>
                          <svg-icon :name="subItem2.icon" fill="#fff" />
                        </el-icon>
                        <template #title>{{ subItem2.name }}</template>
                      </el-menu-item>
                    </template>
                  </el-sub-menu>
                </template>
                <template v-else>
                  <el-menu-item
                    v-if="subItem.isShow"
                    :index="subItem.path"
                    :key="subItem.path"
                  >
                    <el-icon>
                      <svg-icon :name="subItem.icon" fill="#fff" />
                    </el-icon>
                    <template #title>{{ subItem.name }}</template>
                  </el-menu-item>
                </template>
              </template>
            </el-sub-menu>
          </template>
          <template v-else>
            <el-menu-item
              :index="item.path"
              :key="item.path"
            >
              <el-icon>
                <svg-icon :name="item.icon" fill="#fff" />
              </el-icon>
              <template #title>{{ item.name }}</template>
            </el-menu-item>
          </template>
      </template>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { useSidebarStore } from "../store/sidebar";
import { useRoute } from "vue-router";
import { usePermissStore } from "@/store/permiss";

const permiss = usePermissStore();

const menuList = [
  {
    icon: "dashboard",
    path: "/dashboard",
    name: "系统首页",
  },
  ...permiss.getMenuList(),
];
const route = useRoute();
const onRoutes = computed(() => {
  return route.path;
});

const sidebar = useSidebarStore();
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 200px;
}
.sidebar > ul {
  height: 100%;
}
</style>
